package interview.hw_od;

import java.util.HashMap;
import java.util.Scanner;

/**
 * 跳房子 https://codefun2000.com/p/P1348
 */
public class Hopscotch {

    /**
     * 注意审题，题目要求索引和 最小的步数组合，故需记录当前满足的最小索引和以及result，在循环中更新
     * 在插入map时使用putIfAbsent 不存在才插入，保持相同元素的最小索引
     */
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        String[] split = s.substring(1, s.length() - 1).split(",");
        int[] nums = new int[split.length];
        for (int i = 0;i < nums.length;i++) {
            nums[i] = Integer.parseInt(split[i]);
        }
        int target = Integer.parseInt(sc.nextLine());
        //Map<值, 索引>
        HashMap<Integer, Integer> map = new HashMap<>();
        int minIndex = Integer.MAX_VALUE;
        String result = "";
        for (int i = 0;i < nums.length;i++) {
            if (map.containsKey(target-nums[i])) {
                int fi = map.get(target-nums[i]);
                if (fi + i < minIndex) {
                    minIndex = fi + i;
                    result = String.format("[%d, %d]", target-nums[i], nums[i]);
                }
            }
            //不存在则插入，保持相同元素的最小索引
            map.putIfAbsent(nums[i], i);
        }
        System.out.println(result);
    }
}
